//
//  ZGLImageCollectionViewCell.m
//  Faker
//
//  Created by dllo on 15/11/4.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "ZGLImageCollectionViewCell.h"
#import "ZGLSubDetModel.h"
#import <UIImageView+AFNetworking.h>

@interface ZGLImageCollectionViewCell ()

@property (nonatomic, strong) UIImageView *bigImage;
@property (nonatomic, strong) UILabel *titleLabel;

@end


@implementation ZGLImageCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.bigImage = [[UIImageView alloc] init];
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.bigImage];
        [self.contentView addSubview:self.titleLabel];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    [super applyLayoutAttributes:layoutAttributes];
    self.backgroundColor = foreColor;
    [self.bigImage setFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    [self.titleLabel setFrame:CGRectMake(ScaleX * 20, ScaleY * 200, ScaleX * 335, ScaleY * 20)];
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.shadowColor = [UIColor blackColor];
    self.titleLabel.shadowOffset = CGSizeMake(0.1, 0.1);
    
}
- (void)setSubDetModel:(ZGLSubDetModel *)subDetModel {
    if (_subDetModel != subDetModel) {
        _subDetModel = subDetModel;
    }
    if (subDetModel.media.count == 0) {
        [self.bigImage setImage:[UIImage imageNamed:@"nopic"]];
    } else {
        [self.bigImage setImageWithURL:[NSURL URLWithString:subDetModel.media[0][@"url"]] placeholderImage:[UIImage imageNamed:@"nopic"]];
    }
    self.titleLabel.text = subDetModel.title;
}

@end
